﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace BoilerplateWPF.Helpers
{
    /// <summary>
    /// 消息框帮助类，提供各种类型的消息提示功能
    /// </summary>
    public static class MsgBoxHelper
    {
        #region 基础消息框

        /// <summary>
        /// 显示信息提示框
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题（可选）</param>
        public static void Information(string message, string title = "提示")
        {
            MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Information);
        }

        /// <summary>
        /// 显示警告提示框
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题（可选）</param>
        public static void Warning(string message, string title = "警告")
        {
            MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Warning);
        }

        /// <summary>
        /// 显示错误提示框
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题（可选）</param>
        public static void Error(string message, string title = "错误")
        {
            MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error);
        }

        /// <summary>
        /// 显示成功提示框
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题（可选）</param>
        public static void Success(string message, string title = "成功")
        {
            MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Information);
        }

        #endregion

        #region 询问对话框

        /// <summary>
        /// 显示Yes/No询问对话框
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题（可选）</param>
        /// <returns>用户选择结果</returns>
        public static bool ConfirmYesNo(string message, string title = "请确认")
        {
            var result = MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question);
            return result == MessageBoxResult.Yes;
        }

        /// <summary>
        /// 显示Yes/No/Cancel询问对话框
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题（可选）</param>
        /// <returns>用户选择结果</returns>
        public static MessageBoxResult ConfirmYesNoCancel(string message, string title = "请确认")
        {
            return MessageBox.Show(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
        }

        /// <summary>
        /// 显示OK/Cancel询问对话框
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题（可选）</param>
        /// <returns>用户选择结果</returns>
        public static bool ConfirmOkCancel(string message, string title = "请确认")
        {
            var result = MessageBox.Show(message, title, MessageBoxButton.OKCancel, MessageBoxImage.Question);
            return result == MessageBoxResult.OK;
        }

        #endregion

        #region 异常处理

        /// <summary>
        /// 显示异常信息对话框
        /// </summary>
        /// <param name="ex">异常对象</param>
        /// <param name="friendlyMessage">友好提示信息（可选）</param>
        public static void ShowException(Exception ex, string friendlyMessage = null)
        {
            var message = string.IsNullOrEmpty(friendlyMessage)
                ? ex.Message
                : $"{friendlyMessage}\n\n错误详情：{ex.Message}";

            MessageBox.Show(message, "发生错误", MessageBoxButton.OK, MessageBoxImage.Error);
        }

        /// <summary>
        /// 显示异常详细信息对话框（包含堆栈跟踪）
        /// </summary>
        /// <param name="ex">异常对象</param>
        public static void ShowExceptionDetail(Exception ex)
        {
            var message = $"错误信息：{ex.Message}\n\n堆栈跟踪：{ex.StackTrace}";
            MessageBox.Show(message, "错误详情", MessageBoxButton.OK, MessageBoxImage.Error);
        }

        #endregion

        #region 高级功能

        /// <summary>
        /// 在指定父窗口显示消息框
        /// </summary>
        /// <param name="owner">父窗口</param>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题</param>
        /// <param name="button">按钮类型</param>
        /// <param name="icon">图标类型</param>
        /// <returns>对话框结果</returns>
        public static MessageBoxResult Show(Window owner, string message, string title,
                                          MessageBoxButton button = MessageBoxButton.OK,
                                          MessageBoxImage icon = MessageBoxImage.Information)
        {
            return MessageBox.Show(owner, message, title, button, icon);
        }

        /// <summary>
        /// 显示自定义图标的消息框（通过扩展方法实现）
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="title">标题</param>
        /// <param name="button">按钮类型</param>
        /// <param name="icon">自定义图标（可选）</param>
        /// <returns>对话框结果</returns>
        public static MessageBoxResult ShowCustom(string message, string title,
                                                MessageBoxButton button = MessageBoxButton.OK,
                                                ImageSource icon = null)
        {
            // 这里可以扩展为使用自定义窗口来实现带图标的对话框
            // 目前先使用标准消息框
            return MessageBox.Show(message, title, button, MessageBoxImage.Information);
        }

        #endregion

        #region 快捷方法

        /// <summary>
        /// 快速显示调试信息（仅在DEBUG模式下显示）
        /// </summary>
        /// <param name="message">调试信息</param>
        [System.Diagnostics.Conditional("DEBUG")]
        public static void Debug(string message)
        {
            MessageBox.Show($"[DEBUG] {message}", "调试信息", MessageBoxButton.OK, MessageBoxImage.Asterisk);
        }

        /// <summary>
        /// 显示操作完成提示
        /// </summary>
        /// <param name="operationName">操作名称</param>
        public static void OperationCompleted(string operationName)
        {
            Information($"{operationName} 操作已完成", "操作成功");
        }

        #endregion
    }
}
